/***********************************************************************************
    Filename: hal_rf.h

    Copyright 2007 Texas Instruments, Inc.
***********************************************************************************/

#ifndef HAL_RF_H
#define HAL_RF_H

#include "hal_types.h"

//----------------------------------------------------------------------------------
// Type declarations
//----------------------------------------------------------------------------------
typedef struct {
    uint8 iocfg2;           // GDO2Output Pin Configuration
    uint8 iocfg1;           // GDO1Output Pin Configuration
    uint8 iocfg0;           // GDO0Output Pin Configuration
    uint8 fifothr;          // RX FIFO and TX FIFO Thresholds
    uint8 sync1;            // Sync Word, High Byte
    uint8 sync0;            // Sync Word, Low Byte
    uint8 pktlen;           // Packet Length
    uint8 pktctrl1;         // Packet Automation Control
    uint8 pktctrl0;         // Packet Automation Control
    uint8 addr;             // Device Address
    uint8 channr;           // Channel Number
    uint8 fsctrl1;          // Frequency Synthesizer Control
    uint8 fsctrl0;          // Frequency Synthesizer Control
    uint8 freq2;            // Frequency Control Word, High Byte
    uint8 freq1;            // Frequency Control Word, Middle Byte
    uint8 freq0;            // Frequency Control Word, Low Byte
    uint8 mdmcfg4;          // Modem Configuration
    uint8 mdmcfg3;          // Modem Configuration
    uint8 mdmcfg2;          // Modem Configuration
    uint8 mdmcfg1;          // Modem Configuration
    uint8 mdmcfg0;          // Modem Configuration
    uint8 deviatn;          // Modem Deviation Setting
    uint8 mcsm2;            // Main Radio Control State Machine Configuration
    uint8 mcsm1;            // Main Radio Control State Machine Configuration
    uint8 mcsm0;            // Main Radio Control State Machine Configuration
    uint8 foccfg;           // Frequency Offset Compensation Configuration
    uint8 bscfg;            // Bit Synchronization Configuration
    uint8 agcctrl2;         // AGC Control
    uint8 agcctrl1;         // AGC Control
    uint8 agcctrl0;         // AGC Control
    uint8 worevt1;          // High Byte Event0 Timeout
    uint8 worevt0;          // Low Byte Event0 Timeout
    uint8 worctrl;          // Wake On Radio Control
    uint8 frend1;           // Front End RX Configuration
    uint8 frend0;           // Front End TX configuration
    uint8 fscal3;           // Frequency Synthesizer Calibration
    uint8 fscal2;           // Frequency Synthesizer Calibration
    uint8 fscal1;           // Frequency Synthesizer Calibration
    uint8 fscal0;           // Frequency Synthesizer Calibration
    uint8 rcctrl1;          // RC Oscillator Configuration
    uint8 rcctrl0;          // RC Oscillator Configuration
    uint8 fstest;           // Frequency Synthesizer Calibration Control
    uint8 ptest;            // Production Test
    uint8 agctest;          // AGC Test
    uint8 test2;            // Various Test Settings
    uint8 test1;            // Various Test Settings
    uint8 test0;            // Various Test Settings
    uint8 partnum;          // Chip ID
    uint8 version;          // Chip ID
    uint8 freqest;          // Frequency Offset Estimate from Demodulator
    uint8 lqi;              // Demodulator Estimate for Link Quality
    uint8 rssi;             // Received Signal Strength Indication
    uint8 marcstate;        // Main Radio Control State Machine State
    uint8 wortime1;         // High Byte of WOR Time
    uint8 wortime0;         // Low Byte of WOR Time
    uint8 pktstatus;        // Current GDOxStatus and Packet Status
    uint8 vco_vc_dac;       // Current Setting from PLL Calibration Module
    uint8 txbytes;          // Underflow and Number of Bytes
    uint8 rxbytes;          // Underflow and Number of Bytes
    uint8 rcctrl1_status;   // Last RC Oscillator Calibration Result
    uint8 rcctrl0_status;   // Last RC Oscillator Calibration Result
} HAL_RF_CONFIG;

extern const HAL_RF_CONFIG rfSettings;
extern const uint8 au8PaTable[8];

// The chip status byte, returned by chip for all SPI accesses
typedef uint8 HAL_RF_STATUS;

// NES controller
typedef struct
{
	uint8 nesUp			:1;
	uint8 nesDown		:1;
	uint8 nesLeft		:1;
	uint8 nesRight		:1;
	uint8 nesSelect		:1;
	uint8 nesStart		:1;
	uint8 nesA			:1;
	uint8 nesB			:1;
} NES_BOTTON;

// Transmission message structure
typedef struct
{
	NES_BOTTON tNesBotton;
	uint8      u8Reserved1;
	uint8      u8Reserved2;
	uint8      u8Reserved3;
}RF_RX_MSG;

extern RF_RX_MSG tRfRxMsg;



//----------------------------------------------------------------------------------
// Function declarations
//----------------------------------------------------------------------------------

void  halRfSetupChip(const HAL_RF_CONFIG* rfConfig, const uint8* rfPaTable, uint8 rfPaTableLen);
void  halRfResetChip(void);
uint8 halRfGetChipId(void);
uint8 halRfGetChipVer(void);
uint8 halRfReadStatusReg(uint8 addr);
uint8 halRfReadReg(uint8 addr);

HAL_RF_STATUS halRfWriteReg(uint8 addr, uint8 data);
HAL_RF_STATUS halRfWriteFifo(const uint8* data, uint8 length);
HAL_RF_STATUS halRfReadFifo(uint8* data, uint8 length);
HAL_RF_STATUS halRfStrobe(uint8 cmd);
HAL_RF_STATUS halRfGetTxStatus(void);
HAL_RF_STATUS halRfGetRxStatus(void);


/**********************************************************************************/
#endif
